package cl.thesouthfun.mantenedor.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper{

	public static String SQL_CREATE;
	public static String SQL_UPGRADE;


	public static String DATABASE_NAME;
	public static String DATABASE_VERSION;

	private Database database;
	private final Context nContext;
	private SQLiteDatabase sqLiteDatabase;


	private static class Database extends SQLiteOpenHelper {

		public Database(Context context, String name, CursorFactory factory, int version) {
			super(context, name, factory, version);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			db.execSQL(SQL_CREATE);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			db.execSQL(SQL_UPGRADE);
			onCreate(db);
		}

	}
		
	public DatabaseHelper (Context c){
		nContext = c;
	}
	
	public DatabaseHelper open(String databaseName, int databaseVersion) throws Exception{
		database = new Database(nContext, databaseName, null, databaseVersion);
		sqLiteDatabase = database.getWritableDatabase();
		return this;
	}
	
	public SQLiteDatabase getSqLiteDatabase() {
		return sqLiteDatabase;
	}

	public void setSqLiteDatabase(SQLiteDatabase sqLiteDatabase) {
		this.sqLiteDatabase = sqLiteDatabase;
	}
	
	public void close(){
		database.close();
	}
	
}
